local skynet = require "skynet"
local filelog = require "filelog"
local socket = require "socket"
local msghelper = require "agenthelper"
local configdao = require "configdao"
local base = require "base"
local serverbase = require "serverbase"
local table = table
require "skynet.manager"

local params = ...

local Agent = serverbase:new({
		session_id = nil,
		session_begin_time = 0,
		session_timeout = 0,
		watchdog = nil,
		client_fd = 0,
	}) 

function Agent:tostring()
	return "gmsvrd agent"
end

local function agent_to_string()
	return Agent:tostring()
end

function  Agent:init()
	msghelper:init(Agent)
	self.eventmng.init(Agent)
	self.eventmng.add_eventbyname("cmd", "agentcmd")
	self.eventmng.add_eventbyname("request", "agentrequest")
	Agent.__tostring = agent_to_string						
end

function Agent:timeout()
	self:agentexit()
end

function Agent:agentexit()
	--做一些退出前处理
	skynet.send(skynet.getenv("svr_id"), "lua", "cmd", "agentexit", self.session_id)
	skynet.exit()	
end

function Agent:clear()
	
end

skynet.start(function()
	if params == nil then
		Agent:start()
	else		
		Agent:start(table.unpack(base.strsplit(params, ",")))
	end	
end)
